#include "vlog/vlog.h"
#include <filesystem>
#include <fstream>
#include <iostream>

vlog::Logger::ptr logger = VLOG_GET_ROOT();
namespace fs = std::filesystem;

void DisplayDirectoryTree(const fs::path& pathToScan, int level = 0)
{
    for (const auto& entry : fs::directory_iterator(pathToScan))
    {
        const auto filenameStr = entry.path().filename().string();
        // 目录
        if (entry.is_directory())
        {
            std::cout << std::setw(level * 3) << "" << filenameStr << "\n";
            DisplayDirectoryTree(entry, level + 1);
        }
        else if (entry.is_regular_file())
        {
            std::cout << std::setw(level * 3) << filenameStr << ", size " << fs::file_size(entry) << "bytes\n";
        }
        else
        {
            std::cout << std::setw(level * 3) << ""
                      << " [?] " << filenameStr << "\n";
        }
    }
}

int main(int argc, char* argv[])
{

    try
    {
        const fs::path path{argc >= 2 ? argv[1] : fs::current_path()};
        std::cout << "listing files in the directory: " << fs::absolute(path).string() << "\n";
        logger->SetLogLevel(vlog::LogLevel::Level::ERROR);
        VLOG_ERROR(logger) << "123";
        // DisplayDirectoryTree(path);
    }
    catch (const std::exception& e)
    {
        std::cerr << "filesystem error" << e.what() << '\n';
    }

    return 0;
}